import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import BasicLayout from '@/layouts/BasicLayout'
// import BasicLayout from '@/layouts/BasicLayout.horizontal'
export { BasicLayout }

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: 'noRedirect'           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'anticon'/'#svg-icon'  the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    refresh: false               if set true, the page can be refresh(default is false)
    group: {                     tag 共享组（未实现）
      attr                       tag 共享组的属性配置
      name                       tag 共享组的名称配置
    }
    webview: {                   当 path 值是以 URL 开始，那么控制链接是内链还是外部链接（未实现）
      type: 'inner'/'outer'      指定打开网页，是以浏览器新开窗口，还是直接链接到内部
      fullscreen: true           当 webview.type 是 'inner'，是否添加全屏插件，默认添加
    }
  }
 */

export const constantRoutes = [
  {
    path: '/redirect',
    name: 'Redirect',
    component: BasicLayout,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/Redirect.vue')
      }
    ]
  },
  {
    path: '/error/:status',
    name: 'UnknowError',
    component: () => import(/* webpackChunkName: "Exception" */ '@/views/Exception.vue')
  },
  {
    path: '/404',
    name: 'NotFound',
    component: () => import(/* webpackChunkName: "Exception" */ '@/views/Exception.vue')
  },
  {
    path: '/login',
    name: 'UserLogin',
    component: () => import('@/views/User/login/index.vue')
  }
]

export const AnyRouteRecord = { path: '*', redirect: '/404' }

const createRouter = () => new Router({
  base: process.env.BASE_URL,
  scrollBehavior: () => ({ x: 0, y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router
